package com.yootk.action;

import com.yootk.action.abs.AbstractAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import java.util.concurrent.TimeUnit;

@Controller
@RequestMapping("/pages/session/*")
@SessionAttributes({"user","role"})
public class SessionAction extends AbstractAction {
    private static final Logger LOGGER = LoggerFactory.getLogger(SessionAction.class) ;
    @GetMapping("get")
    public ModelAndView get(Model model){
        LOGGER.info("user={}",model.getAttribute("user"));
        LOGGER.info("role={}",model.getAttribute("role"));
        return null ;
    }
    @GetMapping("clean")
    public ModelAndView clean (ModelMap model, SessionStatus status) throws Exception{
        LOGGER.info("user={}",model.getAttribute("user"));
        LOGGER.info("role={}",model.getAttribute("role"));
        status.setComplete();
        TimeUnit.SECONDS.sleep(5);
        LOGGER.info("user={}",model.getAttribute("user"));
        LOGGER.info("role={}",model.getAttribute("role"));
        return null ;
    }
}
